<?php
/**
 * Description of ChatService
 *
 * @author Magno
 */
class ChatService {


    private $chatDAO;
    function __construct() {
        $this->chatDAO = new ChatDAO();
    }


    public function salvar($chat) {

        try {
            return $this->chatDAO->salvar($chat);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function salvarSimples($chatID, $leilaoID, $usuarioID) {

        try {
            return $this->chatDAO->salvarSimples($chatID, $leilaoID, $usuarioID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function excluir($chatID) {

        try {
            if(!isset ($chatID) || $chatID <= 0)
                throw new Exception("Codigo do Chat Nao Econtrado!!!");

            $this->chatDAO->excluir($chatID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }

    }

    public function listar($pagina = 0, $leilaoID = -1, $usuarioID = -1, $carregarDependencias = false) {
        try {
            return $this->chatDAO->listar($pagina, $leilaoID, $usuarioID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function listarPorOrdem($pagina = 0, $tamanho = 0, $ordem = "chatID", $direcao = "DESC", $carregarDependencias = false) {
        try {
            return $this->chatDAO->listarPorOrdem($pagina, $tamanho, $ordem, $direcao, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function buscarPorID($chatID, $carregarDependencias = false) {
        try {
            if(!isset ($chatID) || $chatID <= 0)
                throw new Exception("Codigo do Chat Nao Econtrado!!!");
            return $this->chatDAO->buscarPorID($chatID, $carregarDependencias);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }

    public function total($leilaoID = -1, $usuarioID = -1) {
        try {
            return $this->chatDAO->total($leilaoID, $usuarioID);
        }catch(Exception $err) {
            throw new Exception($err->getMessage());
        }
    }
}
?>
